<template>
  <div>
    <div style="height: 1100px">
      <FormPanel
        ref="formPanel"
        :cols="3"
        :labelWidth="80"
        :list="formList"
        formType="show"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
        style="margin-top: 20px"
      />
    </div>
  </div>
</template>

<script>
import { getDealerCompanyByCode} from "@/api/common/org/dealerCompany";
import { dictionary } from '@/utils/dictMixin';
import { formatDat } from '@/utils/validate'
import { getlistAllData} from "@/api/common/org/dealerCompany";
export default {
  name: 'BasicInfo',
  mixins: [dictionary],
  /* props: {
    rowData: {
      type: Object,
      default: () => ({})
    },
    listAllData:{
      type:Array,
      default:()=>([])
    },
    isOk:{
      type:Boolean,
      default:false
    },
  }, */
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      listAllData:[],
      isOk:false
    };
  },
  watch: {
      isOk(oldval,newval){
        console.log(oldval,"123")
        if(oldval){
          this.formList.forEach(ele => {
            this.listAllData.forEach(x=>{
              if(x.regionId == ele.initialValue){
                ele.initialValue=x.regionName
              }
            })
          });
        }
      }
  },
  created() {
    this.getDealer();
  },
  
  methods: {
    async getDealer() {
      let res = await getDealerCompanyByCode(this.saveData);
      this.formList.forEach(x => {
        x.initialValue = res.data[x.fieldName];
      });
      console.log(formatDat(res.data['openDate']),res.data['openDate'],"res.data['openDate']")
      this.formList.find(item=>item.fieldName == "openDate").initialValue=formatDat(res.data['openDate']);
      await getlistAllData().then(res=>{
         this.listAllData=res.data
         this.isOk=true
       })
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '公司代码',
          fieldName: 'companyCode',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '公司名称',
          fieldName: 'companyNameCN',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '公司简称',
          fieldName: 'companyNameEN',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '省',
          fieldName: 'provinceId',
          initialValue: '',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '市',
          fieldName: 'cityId',
          // placeholder: '请选择',
          // itemList: this.createDictText('1000')
        },
        {
          type: 'INPUT',
          label: '区/县',
          fieldName: 'county',
          // placeholder: '请选择',
          // itemList: this.createDictText('1000')
        },

        {
          type: 'INPUT',
          label: '地址',
          fieldName: 'addressCn',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '联系电话',
          fieldName: 'phone',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '传真',
          fieldName: 'fax',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: 'EMAIL',
          fieldName: 'eMail',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode',
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '公司状态',
          fieldName: 'dealerStatus',
          placeholder: '请选择',
          itemList: this.createDictList('1001'),
          //rules: [{ required: true, message: '请选择是否有效', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '公司主页',
          fieldName: 'companyHomepage',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '开业时间',
          fieldName: 'openDate',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          initialValue: '',
        }
      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
  }

};
</script>
